package com.yunji.framework_template.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yunji.framework_template.biz.service.SitesCommentService;
import com.yunji.framework_template.common.web.Page;
import com.yunji.framework_template.common.web.Result;
import com.yunji.framework_template.orm.persistence.model.SitesComment;

/**
 * Created by fenglibin on 2018/11/15.
 */
@Controller
@RequestMapping("/sitesComment/")
public class SitesCommentController {

    @Autowired
    SitesCommentService sitesCommentService;

    @RequestMapping("selectAll")
    @ResponseBody
    public Result<List<SitesComment>> selectAll() {
        return Result.success(sitesCommentService.selectAll());
    }

    @RequestMapping("select")
    @ResponseBody
    public Result<SitesComment> selectByPrimaryKey(Integer id) {
        return Result.success(sitesCommentService.selectByPrimaryKey(id));
    }

    @RequestMapping("selectByCondition")
    @ResponseBody
    public Result<List<SitesComment>> selectByCondition(SitesComment record) {
        return Result.success(sitesCommentService.selectByCondition(record));
    }

    @RequestMapping("count")
    @ResponseBody
    public Result<Integer> count(SitesComment record) {
        return Result.success(sitesCommentService.count(record));
    }

    @RequestMapping("insert")
    @ResponseBody
    public Result<Integer> insertSelective(SitesComment record) {
        return Result.success(sitesCommentService.insertSelective(record));
    }

    @RequestMapping("update")
    @ResponseBody
    public Result<Integer> updateByPrimaryKeySelective(SitesComment record) {
        return Result.success(sitesCommentService.updateByPrimaryKeySelective(record));
    }

    @RequestMapping("selectByPage")
    @ResponseBody
    public Result<Page<List<SitesComment>>> selectByPage(Page<SitesComment> page) {
        List<SitesComment> list = null;
        page = page.sequentialDisplayCalculate(sitesCommentService.count(page.getObj()));
        if (page.getTotalCount() > 0) {
            list = sitesCommentService.selectByPage(page);
        }
        Page<List<SitesComment>> result = new Page<List<SitesComment>>(page, list);
        return Result.success(result);
    }

    @RequestMapping("deleteByCondition1")
    @ResponseBody
    public Result<Integer> deleteByCondition(SitesComment record) {
        return Result.success(sitesCommentService.deleteByCondition(record));
    }

    @RequestMapping("delete1")
    @ResponseBody
    public Result<Integer> deleteByPrimaryKey(Integer id) {
        return Result.success(sitesCommentService.deleteByPrimaryKey(id));
    }

    @RequestMapping("updateByPrimaryKeyWithBLOBs")
    @ResponseBody
    public Result<Integer> updateByPrimaryKeyWithBLOBs(SitesComment record) {
        return Result.success(sitesCommentService.updateByPrimaryKeyWithBLOBs(record));
    }

}
